package com.songshuai.webapi.jobapi.common.enumerations;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public enum SubjectEnglishType {
    YuWen(1003001, "chinese"),
    ShuXue(1003002, "math"),
    HuaXue(1003003, "chemistry"),
    Yingyu(1003004, "english"),
    WuLi(1003005, "physics"),
    QiTa(1003006, "other"),
    KeXue(1003007, "科学"),
    JiSuanJi(1003008, "计算机");
    private int code;
    private String msg;

    SubjectEnglishType(int code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public static int getCode(String define){
        try {
            return SubjectEnglishType.valueOf(define).code;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return 0;
        }
    }

    public static String getMsg(String define){
        try {
            return SubjectEnglishType.valueOf(define).msg;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return "";
        }
    }

    public static String getMsg(Integer code){
        if(code==null||code<=0)
            return "";
        for(SubjectEnglishType err : SubjectEnglishType.values()){
            if(err.code==code){
                return err.msg;
            }
        }
        return "";
    }

    public int getCode(){
        return code;
    }

    public String getMsg(){
        return msg;
    }
}
